<?php
	namespace app\index\controller;

	use \think\Db;

	class Adver extends Base{
		public function index(){
			try{
				$row=$this->getAdver();

				$type=input('get.type');

				$arr=['index_jdt','index_header','index_footer','header','footer'];

				if(in_array($type,$arr)){

					$row2=[];

					foreach($row as $k=>$v){
						if($k==$type){
							$row2=$v;

							break;
						}
					}

					$row=$row2;
				}

				

				return $this->data($row);
			}catch(\Exception $e){
				$this->err($e);
			}
		}

		private function getAdver(){
			try{
				$adver=$this->me->get('adver');

				if(!$adver){
					$adver=[];

					$row=Db::name('adver')->where(['a_display'=>1])->select();

					foreach($row as $k=>$v){
						$adver[$v['a_posi']][]=$v;
					}

					$this->me->set('adver',$adver);
				}

				return $adver;
			}catch(\Exception $e){
				$this->err($e);
			}
		}
	}
?>